﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BanXeTang
{
    public class Options
    {
        private int _viTriHighLight;

        public int ViTriHighLight
        {
            get { return _viTriHighLight; }
            set { _viTriHighLight = value; }
        }

        private int _nOptions;

        public int NOptions
        {
            get { return _nOptions; }
            set { _nOptions = value; }
        }

       
        public Options()
        {
            _viTriHighLight = 0;
            _nOptions = 2;
        }

        public void Update(GameTime gameTime)
        {
            Input.lastKeyboardState = Input.keyboardState;
            Input.keyboardState = Keyboard.GetState();
            if (Input.lastKeyboardState.IsKeyDown(Keys.Down) && Input.keyboardState.IsKeyUp(Keys.Down) && _viTriHighLight < _nOptions - 1)
            {
                if (AmThanh.moAmThanh)
                    AmThanh.drip.Play();
                _viTriHighLight++;
            }
            if (Input.lastKeyboardState.IsKeyDown(Keys.Up) && Input.keyboardState.IsKeyUp(Keys.Up) && _viTriHighLight > 0)
            {
                if (AmThanh.moAmThanh)
                    AmThanh.drip.Play();
                _viTriHighLight--;
            }
            switch (_viTriHighLight)
            {
                case 0://Lựa chọn tắt mở nhạc
                    {
                        if (Input.lastKeyboardState.IsKeyDown(Keys.Y) && Input.keyboardState.IsKeyUp(Keys.Y))
                            AmThanh.moNhac = true;
                        if (Input.lastKeyboardState.IsKeyDown(Keys.N) && Input.keyboardState.IsKeyUp(Keys.N))
                            AmThanh.moNhac = false;
                        break;
                    }
                case 1://Lựa chọn tắt mở hiệu ứng âm thanh
                    {
                        if (Input.lastKeyboardState.IsKeyDown(Keys.Y) && Input.keyboardState.IsKeyUp(Keys.Y))
                            AmThanh.moAmThanh = true;
                        if (Input.lastKeyboardState.IsKeyDown(Keys.N) && Input.keyboardState.IsKeyUp(Keys.N))
                            AmThanh.moAmThanh = false;
                        break;
                    }
            }
            if (Input.lastKeyboardState.IsKeyDown(Keys.Escape) && Input.keyboardState.IsKeyUp(Keys.Escape))
            {
                Game1.trangThai = 0;
                Game1.viTriChon = -1;
                Game1.viTriHighLight = 0;
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            switch (_viTriHighLight)
            {
                case 0:
                    {
                        if (AmThanh.moNhac)
                            spriteBatch.DrawString(GlobalSettings.fontChu, "Bat nhac nen (Y/N): Y", new Vector2(10, 120),  Color.Red);
                        else
                            spriteBatch.DrawString(GlobalSettings.fontChu, "Bat nhac nen (Y/N): N", new Vector2(10, 120), Color.Red);
                        if (AmThanh.moAmThanh)
                            spriteBatch.DrawString(GlobalSettings.fontChu, "Bat am thanh (Y/N): Y", new Vector2(10, 150), Color.Black);
                        else
                            spriteBatch.DrawString(GlobalSettings.fontChu, "Bat am thanh (Y/N) N", new Vector2(10, 150), Color.Black);
                        break;
                    }
                case 1:
                    {
                        if (AmThanh.moNhac)
                            spriteBatch.DrawString(GlobalSettings.fontChu, "Bat nhac nen (Y/N): Y", new Vector2(10, 120), Color.Black);
                        else
                            spriteBatch.DrawString(GlobalSettings.fontChu, "Bat nhac nen (Y/N): N", new Vector2(10, 120), Color.Black);
                        if (AmThanh.moAmThanh)
                            spriteBatch.DrawString(GlobalSettings.fontChu, "Bat am thanh (Y/N): Y", new Vector2(10, 150), Color.Red);
                        else
                            spriteBatch.DrawString(GlobalSettings.fontChu, "Bat am thanh (Y/N): N", new Vector2(10, 150), Color.Red);
                        break;
                    }
            }
        }
    }
}
